package com.jiashihui.schema_lgorithm.java.socket.handler.impl.heartbeat;

import com.jiashihui.schema_lgorithm.java.socket.handler.common.IServiceHandler;
import com.jiashihui.schema_lgorithm.java.socket.handler.common.ServiceHandlerEvent;
import com.jiashihui.schema_lgorithm.java.socket.handler.common.ServiceTypeEnum;
import io.netty.channel.ChannelHandlerContext;
import org.jsoup.helper.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class PDAHeartbeatHandler implements IServiceHandler {
    private static final Logger LOGGER = LoggerFactory.getLogger(PDAHeartbeatHandler.class);
    @Autowired
    private ApplicationContext context;

    @PostConstruct
    public void init() {
        ServiceHandlerEvent event = new ServiceHandlerEvent(this);
        context.publishEvent(event);
    }

    @Override
    public ServiceTypeEnum getServiceType() {
        return ServiceTypeEnum.ANCB_PDA_HB;
    }

    @Override
    public String handler(String req) {
        LOGGER.info("接收到的信息: {}", req);
        if (StringUtil.isBlank(req)) {
            return "请求内容为空";
        }
        return "{\"heartbeat\":\"hb_request\", \"aa\":\"bbb\"}";
    }

    @Override
    public String handler(ChannelHandlerContext ctx, String req) {
        return null;
    }

}
